<?php
class PayreturnAction extends BaseAction {

    public function index(){
        $order_no = I('get.order_no');
        $map['order_no'] = $order_no;
        $list = M('Order')->where($map)->find();

        $agent = $_SERVER['HTTP_USER_AGENT']; 
        if(strpos($agent,"icroMessenger")) {
            $this->assign('isWeixn','1');
        }       

        if ($list) {
            if ($list['baoxian']==1) {
                $this->display();
            }else{
                $this->display('normal');
            }            
        }else{
            exit('订单不存在');  
        }                
    }

    public function wxnotice(){
        $order_no = I('get.order_no');
        $map['order_no'] = $order_no;
        $list = M('Order')->where($map)->find();
        if ($list) {
            if ($list['payStatus']==0) {
                //更新订单状态
                M('Order')->where($map)->setField('payStatus',1);

                //分销的商品进行佣金分配
                if ($list['baoxian']>0) {
                    # code...
                    unset($map);
                    $map['wxid'] = $list['wxid'];

                    //更新会员组
                    $obj = M('Member');
                    $obj->where($map)->setField('userGroup',1);

                    //减去物流费用
                    $money = $list['money']-$list['paymentMoney'];

                    //保存佣金记录
                    $this->saveYongjin($list['wxid'] , $list['wxid'] , $money);
                }                
            }
        }             
    }
}